package com.sumainfor.pc.gmio.controller.director;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.gmio.service.DiDeferredApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 延期
 */
@RestController
@RequestMapping("/tenant/key/director/DiWxDeferredApply")
public class DiWxDeferredApplyController implements Serializable {
    @Autowired
    private DiDeferredApplyService diDeferredApplyService;

    @Autowired
    private ZpcMktFeign zpcMktFeign;

    /**
     * 延期申请
     */
    @PostMapping("/addDi")
    public JsonResult addDi(@RequestBody Map<String, Object> params) {
        return diDeferredApplyService.addDi(params);
    }

    /**
     * 查询延期申请
     */
    @GetMapping("/getDiDeferredApplyList")
    public JsonResult getDiDeferredApplyList(@RequestParam Map<String, Object> params, Pager pager) {
        JsonResult result = new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        //根据项目楼号室号做筛选
        if (FieldCheckUtil.isMapFieldNotNull(params, new String[]{"ComId"})) {
            List<String> houseIdList = zpcMktFeign.getHouseIdListByBuildAndRoom(params);
            if (houseIdList != null && houseIdList.size() > 0) {
                params.put("houseIdList", houseIdList);
            }
        }

        Integer cout = diDeferredApplyService.getDiDeferredApplyListCount(params);
        if (cout == 0) {
            return pageUtils.getJsonResult(new ArrayList<Map<String, Object>>(), params, cout);
        }
        List<Map<String, Object>> getCommunityList = diDeferredApplyService.getDiDeferredApplyList(params);
        result = pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
}
